/**
 * 撤销委托
 * @param entrustId
 */
function cancelEntrust(entrustId, type) {
    var symbol = document.getElementById("symbol").value;
    var url = "/trade/cancelEntrust.do?random=" + Math.round(Math.random() * 100);
    var param = {entrustId: entrustId, symbol: symbol};
    if (document.getElementById("tradeType") != null) {
        type = document.getElementById("tradeType").value;
    }
    jQuery.post(url, param, function (data) {
        if (data == 0) {
            // bugfix 2017-06-05 需要先判断节点是否存在，否则会报js错误
            // document.getElementById("entrustStatus" + entrustId).innerHTML = evercancelled;
            $("#entrustStatus" + entrustId).html(evercancelled);
            if (type == 3) {
                var currentPage = document.getElementById("currentPage").value;
                var selectChance = document.getElementById("selectChance").value;
                var sevenago = document.getElementById("sevenago").value;
                window.location.href = "/trade/entrust.do?selectChance=" + selectChance + "&currentPage=" + currentPage + "&sevenago=" + sevenago;
                //newCoinLabel
            } else if (symbol == 0) {
                //window.location.href = "/trade/btc.do?tradeType="+type;
            } else {
                //window.location.href = "/trade/ltc.do?tradeType="+type;
            }
        } else if (data == -200) {
            document.getElementById("tradeBtcTips").innerHTML = get$("youfreezebymastercancel");

        }
    });
}

function tradePercentVlaueOnePart(elem, tradeAmount) {
    tradeAmount = accDiv(parseInt(accMul(tradeAmount, 100)), 100);
    var str_tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    if (tradeAmount == 0) {
        document.getElementById("idCurrentPercent").innerHTML = 0;
    } else {
        str = parseInt(accMul(accDiv(elem, tradeAmount), 100));
        stt = parseInt(accDiv(accMul(str, 204), 100));
        if (stt > 204) {
            stt = 204;
        }
        str = str > 100 ? 100 : str;
        document.getElementById("idBar2").style.width = stt + "px";
        document.getElementById("idBar3").style.left = stt - 4 + "px";

        document.getElementById("idCurrentPercent").innerHTML = str;

        document.getElementById("percentCirclebgPosition").className = "percentCirclebgPositionOne" + bgnumber;


        var bgnumber = document.getElementById("tradeType").value;
        if (stt >= 153) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree" + " percentCirclebgPositionBg" + bgnumber;
        } else if (stt >= 101) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        } else if (stt >= 53) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        } else {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        }
    }
}

function tradePercentVlaueTwoPart(elem, tradeMoney) {
    tradeMoney = parseInt(accMul(accDiv(elem, tradeMoney), 100));
    if (tradeMoney == 0) {
        document.getElementById("idCurrentPercent").innerHTML = 0;
    } else {
        stt = parseInt(accDiv(accMul(tradeMoney, 204), 100));
        if (stt > 204) {
            stt = 204;
        }
        document.getElementById("idBar2").style.width = stt + "px";
        document.getElementById("idBar3").style.left = stt - 4 + "px";
        document.getElementById("idCurrentPercent").innerHTML = tradeMoney;
        var bgnumber = document.getElementById("tradeType").value;
        if (stt >= 153) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree" + " percentCirclebgPositionBg" + bgnumber;
        } else if (stt >= 101) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        } else if (stt >= 53) {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        } else {
            document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
            document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo percentCirclebgTransparent";
            document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree percentCirclebgTransparent";
        }
    }
}

function tradePercentVlaueTotal() {
    document.getElementById("idBar2").style.width = "204px";
    document.getElementById("idCurrentPercent").innerHTML = "100";
    document.getElementById("idBar3").style.left = "204px";

    var bgnumber = document.getElementById("tradeType").value;
    document.getElementById("percentCirclebgPosition").className = "percentCirclebgFirst" + " percentCirclebgPositionBg" + bgnumber;
    document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne" + " percentCirclebgPositionBg" + bgnumber;
    document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo" + " percentCirclebgPositionBg" + bgnumber;
    document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree" + " percentCirclebgPositionBg" + bgnumber;
}

function tradeTurnoverValue() {
    tradeTurnoverValue2(0, null);
}
//type :0 默认 type=1 price type=2 amount
function tradeTurnoverValue2(type, event) {
    var isreturn = ctrlAorTab(event);
    if (isreturn) {
        return;
    }
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var tradeAmount = 0;
    var tradeCnyPrice = 0;
    if (type == 2) {
        var amountSelectionStart = getPositionForInput(document.getElementById("tradeAmount"));
        tradeAmount = document.getElementById("tradeAmount").value = checkNumberByName("tradeAmount");
        setCursorPosition(document.getElementById("tradeAmount"), amountSelectionStart);
    } else {
        tradeAmount = document.getElementById("tradeAmount").value;
    }
    if (type == 1) {
        var priceSelectionStart = getPositionForInput(document.getElementById("tradeCnyPrice"));
        tradeCnyPrice = document.getElementById("tradeCnyPrice").value = checkNumberByName("tradeCnyPrice");
        setCursorPosition(document.getElementById("tradeCnyPrice"), priceSelectionStart);
    } else {
        tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    }
    var turnover = tradeAmount * tradeCnyPrice;
    if (turnover != null && turnover.toString().split(".") != null && turnover.toString().split(".")[1] != null && turnover.toString().split(".")[1].length > 4) {
        turnover = turnover.toFixed(4);
    }
    document.getElementById("tradeTurnover").value = turnover;
    if (tradeType == 0) {
        var tradeTurnover = tradeAmount * tradeCnyPrice;
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
            tradePercentVlaueTotal();
            alertTipsSpan(balanceisinsufficient);
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeTurnover), Number(document.getElementById("userBalance").value));
            clearTipsSpan();
        }
    } else {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
            //newCoinLabel
            if (symbol == 0) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs2);
            } else if (symbol == 1) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs3);
            } else if (symbol == 2) {
                tradePercentVlaueTotal();
                alertTipsSpan(ethNotEnough);
            }
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeAmount), Number(document.getElementById("userBalance").value));
            clearTipsSpan();
        }
    }
}
var check = 1;
function submitTradeBtcForm() {
    if (check == 2) {
        return;
    }
    var tradeAmount = document.getElementById("tradeAmount").value;
    var tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    var tradePwd = trim(document.getElementById("tradePwd").value);
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var isopen = document.getElementById("isopen").value;
    var islimited = document.getElementById("limitedType").checked;
    var limited = 0;
    if (!islimited) {
        if (tradeType == 0) {
            var tradeTurnover = tradeAmount * tradeCnyPrice;
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
                alertTipsSpan(balanceisinsufficient);
                return;
            } else {
                clearTipsSpan();
            }
        } else {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan(buytradejs2);
                } else if (symbol == 1) {
                    alertTipsSpan(buytradejs3);
                } else if (symbol == 2) {
                    alertTipsSpan(ethNotEnough);
                }
                return;
            } else {
                clearTipsSpan();
            }
        }
        var reg = new RegExp("^[0-9]+\.{0,1}[0-9]{0,8}$");
        if (!reg.test(tradeAmount)) {
            alertTipsSpan(buytradejs4);
            return;
        } else {
            clearTipsSpan();
        }
        if (tradeAmount < 0.01) {
            //newCoinLabel
            if (symbol == 1) alertTipsSpan(buytradejs5);
            else if (symbol == 0) alertTipsSpan(buytradejs6);
            else if (symbol == 2) alertTipsSpan(get$("ethMinBuyAmount"));
            return;
        } else {
            clearTipsSpan();
        }
        if (!reg.test(tradeCnyPrice)) {
            alertTipsSpan(buytradejs7);
            return;
        } else {
            clearTipsSpan();
        }
    } else {
        limited = 1;
        var limitedMoney = Number(document.getElementById("limitedMoney").value);
        if (tradeType == 0) {
            //newCoinLabel
            var nowPrice = 0;
            if (symbol == 0) {
                nowPrice = accMul(0.01, Number(document.getElementById("nowPrice").value));
            } else if (symbol == 1) {
                nowPrice = accMul(0.1, Number(document.getElementById("nowPrice").value));
            } else if (symbol == 2) {
                nowPrice = accMul(0.1, Number(document.getElementById("nowPrice").value));
            }
            if (limitedMoney < nowPrice) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan(buytradejs21);
                } else if (symbol == 1) {
                    alertTipsSpan(buytradejs22);
                } else if (symbol == 2) {
                    alertTipsSpan(get$("ethMinBuyAmount"));
                }
                return;
            }
        } else {
            //newCoinLabel
            if (symbol == 0) {
                if (limitedMoney < 0.01) {
                    alertTipsSpan(selltradejs1);
                    return;
                }
            } else if (symbol == 1) {
                if (limitedMoney < 0.1) {
                    alertTipsSpan(selltradejs2);
                    return;
                }
            } else if (symbol == 2) {
                if (limitedMoney < 0.1) {
                    alertTipsSpan(get$("ethMinBuyAmount"));
                    return;
                }
            }
        }
        if (tradeType == 0) {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < limitedMoney) {
                alertTipsSpan(balanceisinsufficient);
                return;
            } else {
                clearTipsSpan();
            }
            tradeCnyPrice = limitedMoney;
        } else {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < limitedMoney) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan(buytradejs2);
                } else if (symbol == 1) {
                    alertTipsSpan(buytradejs3);
                } else if (symbol == 2) {
                    alertTipsSpan(ethNotEnough);
                }
                return;
            } else {
                clearTipsSpan();
            }
        }
        tradeAmount = limitedMoney;
    }
    if (tradePwd == "" && isopen != 1) {
        alertTipsSpan(entertransactionpassword);
        return;
    } else {
        document.getElementById("tradeBtcTips").style.display = "";
        document.getElementById("tradeBtcTips").innerHTML = "&nbsp;";
    }
    var url = "";
    if (tradeType == 0) {
        url = "/trade/buyBtcSubmit.do?random=" + Math.round(Math.random() * 100);
    } else {
        url = "/trade/sellBtcSubmit.do?random=" + Math.round(Math.random() * 100);
    }
    tradePwd = isopen == 1 ? "" : tradePwd;
    var param = {
        tradeAmount: tradeAmount,
        tradeCnyPrice: tradeCnyPrice,
        tradePwd: tradePwd,
        symbol: symbol,
        limited: limited
    };
    check = 2;
    jQuery.post(url, param, function (data) {
        var result = eval('(' + data + ')');
        if (result != null) {
            if (result.resultCode != 0) {
                check = 1;
            }
            if (result.resultCode == -1) {
                if (tradeType == 0) {
                    //newCoinLabel
                    if (symbol == 1) alertTipsSpan(buytradejs9);
                    else if (symbol == 0) alertTipsSpan(buytradejs8);
                    else if (symbol == 2) alertTipsSpan(get$("ethMinBuyAmount"));
                } else {
                    //newCoinLabel
                    if (symbol == 1) alertTipsSpan(selltradejs4);
                    else if (symbol == 0) alertTipsSpan(selltradejs3);
                    else if (symbol == 2) alertTipsSpan(get$("ethMinBuyAmount"));
                }
            } else if (result.resultCode == -2) {
                if (result.errorNum == 0) {
                    alertTipsSpan(buytradejs10);
                } else {
                    alertTipsSpan(buytradejs11 + youhave + result.errorNum + chancesleft);
                }
                if (document.getElementById("tradePwd") != null) {
                    document.getElementById("tradePwd").value = "";
                }
            } else if (result.resultCode == -3) {
                alertTipsSpan(buytradejs13);
            } else if (result.resultCode == -4) {
                alertTipsSpan(buytradejs14);
            } else if (result.resultCode == -5) {
                alertTipsSpan(buytradejs15);
            } else if (result.resultCode == -6) {
                okcoinAlert(buytradejs16, null, null, "");
            } else if (result.resultCode == -7) {
                alertTipsSpan(buytradejs17);
                if (document.getElementById("tradePwdDiv") != null) {
                    document.getElementById("tradePwdDiv").style.display = "block";
                    document.getElementById("isopen").value = 0;
                }
            } else if (result.resultCode == -8) {
                alertTipsSpan(entertransactionpassword);
            } else if (result.resultCode == -9) {
                alertTipsSpan(get$("isLend"));
            } else if (result.resultCode == 0) {
                alertTipsSpan(get$("ordersuccess"));
                waitingStationStatic("btnA", insubmiting);
                jQuery('#tradePwd').val('');
                jQuery('#tradeAmount').val('0');
                jQuery('#tradeTurnover').val('0');

                setTimeout(function () {
                    document.getElementById("tradeBtcTips").style.display = "";
                    document.getElementById("tradeBtcTips").innerHTML = "";
                    check = 1;
                    tradeTurnoverValue();
                }, 3000);
                if (tradeType == 0) {
                    clearWaitingStation("btnA", immediatelybuy);
                } else {
                    clearWaitingStation("btnA", immediatelysell);
                }

            } else if (result.resultCode == 2) {
                alertTipsSpan(buytradejs19);
            } else if (result.resultCode == -200) {
                alertTipsSpan(get$("youfreezebymasterxia"));
            } else if (result.resultCode == 3) {
                alertTipsSpan(buytradejs20);
            } else if (result.resultCode == -97) {
                alertTipsSpan(get$("tradesmallamountmore"));
            }
        }
    });
}

function clearTipsSpan() {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = "";
}

function alertTipsSpan(tips) {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = tips;
}

function summoneyValue(event) {
    var isreturn = ctrlAorTab(event);
    if (isreturn) {
        return;
    }
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var tradeTurnover = document.getElementById("tradeTurnover").value = checkNumberByName("tradeTurnover");
    var tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    var tradeAmount = document.getElementById("tradeAmount").value;
    if (tradeCnyPrice != 0) {
        tradeAmount = tradeTurnover / tradeCnyPrice;
    } else {
        tradeAmount = 0;
    }
    if (tradeAmount != null && tradeAmount.toString().split(".") != null && tradeAmount.toString().split(".")[1] != null && tradeAmount.toString().split(".")[1].length > 4) {
        //去掉四舍五入算法，改为直接截取
        //tradeAmount=tradeAmount.toFixed(5);
        //tradeAmount = tradeAmount.substring(0, tradeAmount.length-1);
        var temp = tradeAmount.toString();
        var index = temp.indexOf(".");
        if (index > -1) {
            var t = temp.substr(index + 1);

            if (t.length > 4)
                temp = temp.substring(0, index + 5);

        }
        tradeAmount = Number(temp);
    }
    document.getElementById("tradeAmount").value = tradeAmount;
    var reg = /^(-?\d*)\.?\d{1,4}$/;
    if (tradeTurnover != null && tradeTurnover.toString().split(".") != null && tradeTurnover.toString().split(".")[1] != null && tradeTurnover.toString().split(".")[1].length > 4) {
        if (!reg.test(tradeTurnover)) {
            document.getElementById("tradeTurnover").value = tradeTurnover.substring(0, tradeTurnover.length - 1);
            return false;
        }
    }
    if (tradeType == 0) {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
            tradePercentVlaueTotal();
            alertTipsSpan(balanceisinsufficient);
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeTurnover), Number(document.getElementById("userBalance").value));
            clearTipsSpan();
        }
    } else {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
            //newCoinLabel
            if (symbol == 0) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs2);
            } else if (symbol == 1) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs3);
            } else if (symbol == 2) {
                tradePercentVlaueTotal();
                alertTipsSpan(ethNotEnough);
            }
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeAmount), Number(document.getElementById("userBalance").value));
            clearTipsSpan();
        }
    }
}

function limitedSummoneyValue() {
    var limitedMoney = document.getElementById("limitedMoney");
    var tradeType = document.getElementById("tradeType").value;
    var length = tradeType == 0 ? 2 : 4;
    var priceSelectionStart = getPositionForInput(limitedMoney);
    var money = limitedMoney.value = (function (a) {
        return a.length > 1 ? a.shift().replace(/\D/g, '') + '.' + a.join('').replace(/\D/g, '').slice(0, length) : a[0].replace(/\D/g, '');
    })(limitedMoney.value.split('.'));
    setCursorPosition(limitedMoney, priceSelectionStart);
    var symbol = document.getElementById("symbol").value;
    if (tradeType == 0) {
        var userBalance = Number(document.getElementById("userCnyBalance").value);
        if (money > userBalance) {
            tradePercentVlaueTotal();
            alertTipsSpan(buytradejs1);
            return;
        } else {
            tradePercentVlaueOnePart(Number(money), Number(document.getElementById("userCnyBalance").value));
            clearTipsSpan();
        }
    } else {
        var coinBalance = Number(document.getElementById("userCoinBalance").value);
        if (money > coinBalance) {
            //newCoinLabel
            if (symbol == 0) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs2);
            } else if (symbol == 1) {
                tradePercentVlaueTotal();
                alertTipsSpan(buytradejs3);
            } else if (symbol == 2) {
                tradePercentVlaueTotal();
                alertTipsSpan(ethNotEnough);
            }
            return;
        } else {
            tradePercentVlaueOnePart(Number(money), Number(document.getElementById("userCoinBalance").value));
            clearTipsSpan();
        }
    }
    clearTipsSpan();
}

function getEntrust(status) {
    if (status == 0) {
        jQuery("#selectChance").val("0");
        jQuery("#sevenago").val("0");
        document.getElementById("beginDate").value = "";
        document.getElementById("endDate").value = "";
    } else if (status == 2) {
        jQuery("#selectChance").val("1");
        jQuery("#sevenago").val("0");
        document.getElementById("beginDate").value = "";
        document.getElementById("endDate").value = "";
    }
    document.getElementById("entrustForm").submit();
}

function showSevenDay() {
    jQuery("#sevenago").val("0");
    document.getElementById("beginDate").value = "";
    document.getElementById("endDate").value = "";
    document.getElementById("entrustForm").submit();
}
function showOtherDay() {
    jQuery("#sevenago").val("1");
    document.getElementById("entrustForm").submit();
}
var EntrustExcel = {
    entrustConstans: {
        confirmed: 1,
        noconfirm: 2
    },
    exportExcel: function (isConfirm) {
        var selectChance = jQuery("#selectChance").val();
        var sevenago = jQuery("#sevenago").val();
        var symbol = jQuery("#symbol").val();
        var beginDate = jQuery("#beginDate").val();
        var endDate = jQuery("#endDate").val();
        var currentPage = jQuery(".current_ss").html();
        var href = "/trade/entrust.do?symbol=" + symbol + "&selectChance=" + selectChance + "&sevenago=" + sevenago + "&beginDate=" + beginDate + "&endDate=" + endDate + "&exportExcel=" + 1 + "&currentPage=" + currentPage;
        var hrefLocation = "/trade/entrust.do?symbol=" + symbol + "&selectChance=" + selectChance + "&sevenago=" + sevenago + "&beginDate=" + beginDate + "&endDate=" + endDate + "&currentPage=" + currentPage;
        var page = 50 + (Number(currentPage) || 0);
        var newClickHref = hrefLocation.replace(/currentPage=\d*/, "currentPage=" + page)
        setTimeout(function () {
            window.location.href = newClickHref;
        }, 1000)
        window.location.href = href;
    }
    ,
    queryEntrustLength: function () {
        var selectChance = jQuery("#selectChance").val();
        var sevenago = jQuery("#sevenago").val();
        var symbol = jQuery("#symbol").val();
        var beginDate = jQuery("#beginDate").val();
        var endDate = jQuery("#endDate").val();
        var isConfirm = EntrustExcel.entrustConstans.noconfirm;
        var href = "/trade/entrust.do?symbol=" + symbol + "&selectChance=" + selectChance + "&sevenago=" + sevenago + "&beginDate=" + beginDate + "&endDate=" + endDate + "&exportExcel=" + 1 + "&isConfirm=" + isConfirm;
        jQuery.post(href, function (result) {
            if (result == 0) {
                okcoinAlert(ensureexpottoexcel, true, EntrustExcel.callBack);
            } else {
                EntrustExcel.exportExcel(EntrustExcel.entrustConstans.confirmed);
            }
        });
    },
    callBack: {
        okBack: function () {
            EntrustExcel.exportExcel(EntrustExcel.entrustConstans.confirmed);
        },
        noBack: function () {
        }
    }
};
jQuery("#exportEntrustExcel").on("click", EntrustExcel.exportExcel);
function selectEntrust() {
    var beginDate = document.getElementById("beginDate").value;
    var endDate = document.getElementById("endDate").value;
    if (beginDate == "" && endDate == "") {
        alert(chooseadate);
        return false;
    }
    var date1 = new Date(beginDate.replace(/-/g, "/"));
    var date2 = new Date(endDate.replace(/-/g, "/"));
    if ((Date.parse(date1) - Date.parse(date2)) > 0) {
        alert(startnotexceedend);
        return false;
    }
    document.getElementById("entrustForm").submit();
}

function changeTradeType(index, type, symbol) {
    autoTrade(index, type, symbol);
    document.getElementById("tradeAmount").value = "";
    tradeTurnoverValue();
}

function autoTrade(index, type, symbol) {
    document.getElementById("limitedType").checked = "";
    limitedTypeChange();
    var priceNum = 0;
    var amountNum = 0;
    var tradeType = document.getElementById("tradeType").value;
    if (tradeType == type) {
        type = type == 0 ? 1 : 0;
        if (type == 0) {
            document.getElementById("buyDiv").style.display = "";
            document.getElementById("sellDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "";
            document.getElementById("sellBtcCnyInformation").style.display = "none";
            document.getElementById("buyLi").className = "cur";
            document.getElementById("sellLi").className = "";
            document.getElementById("tradeType").value = 0;
            document.getElementById("priceSpan").innerHTML = immediatelybuy;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + buyamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = buytotalprice;
            document.getElementById("btnA").value = immediatelybuy;
            document.getElementById("btnA").className = "buttonGreen submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = holding + ": ";
            document.getElementById("userBalance").value = document.getElementById("userCnyBalance").value;
            document.getElementById("limitpriceTitle").style.color = "green";
            document.getElementById("proprotionInfo").innerHTML = buyproportion + ":";
            document.getElementById("idBar2").className = "barGreen";
            tradeType = 0;
        } else {
            document.getElementById("sellDiv").style.display = "";
            document.getElementById("buyDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "none";
            document.getElementById("sellBtcCnyInformation").style.display = "";
            document.getElementById("sellLi").className = "cur";
            document.getElementById("buyLi").className = "";
            document.getElementById("tradeType").value = 1;
            document.getElementById("priceSpan").innerHTML = askprice;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + sellamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = selltotalprice;
            document.getElementById("btnA").value = immediatelysell;
            document.getElementById("btnA").className = "buttonRed submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = sellnetamount + ": "
            document.getElementById("userBalance").value = document.getElementById("userCoinBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = sellproportion + ":";
            document.getElementById("idBar2").className = "barRed";
//			document.getElementById("proprotionInfo").style.color = "red";
            tradeType = 1;
        }
    }
    var name = "sell";
    if (tradeType == 1) {
        name = "buy";
    }
    var priceName = name + "Price" + index;
    priceNum = Number(document.getElementById(priceName).value);
    for (var i = 1; i <= index; i++) {
        var amountName = name + "Amount" + i;
        var amount = Number(document.getElementById(amountName).value);
        amountNum = accAdd(amountNum, amount);
    }
    var money = Number(document.getElementById("userBalance").value);
    var moneyNum = amountNum * priceNum;
    if (tradeType == 0) {
        var reg = /^(-?\d*)\.?\d{1,2}$/;
        if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 2) {
            if (!reg.test(money)) {
                var end = money.toString().split(".")[1];
                if (end.length > 2) {
                    end = end.substring(0, 2);
                }
                money = money.toString().split(".")[0] + "." + end;
            }
        }
        if (money < moneyNum) {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeTurnover").value = money;
            tradePercentVlaueTotal();
            summoneyValue(null);
        } else {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeAmount").value = amountNum;
            tradePercentVlaueTwoPart(moneyNum, money);
            tradeTurnoverValue();
        }
    } else {
        var reg = /^(-?\d*)\.?\d{1,4}$/;
        if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 4) {
            if (!reg.test(money)) {
                var end = money.toString().split(".")[1];
                if (end.length > 4) {
                    end = end.substring(0, 4);
                }
                money = money.toString().split(".")[0] + "." + end;
            }
        }
        if (money < amountNum) {
            document.getElementById("tradeAmount").value = money;
            document.getElementById("tradeCnyPrice").value = priceNum;
            tradePercentVlaueTotal();
            tradeTurnoverValue();
        } else {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeAmount").value = amountNum;
            tradePercentVlaueTwoPart(moneyNum, money);
            tradeTurnoverValue();
        }
    }
}
function antoTurnover(money) {

    var reg = /^(-?\d*)\.?\d{1,2}$/;
    if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 2) {
        if (!reg.test(money)) {
            var end = money.toString().split(".")[1];
            if (end.length > 2) {
                end = end.substring(0, 2);
            }
            money = money.toString().split(".")[0] + "." + end;
        }
    }
    document.getElementById("tradeTurnover").value = money;
    document.getElementById("limitedMoney").value = money;
    summoneyValue_new(null);
}
function antoAmount(money) {
    var reg = /^(-?\d*)\.?\d{1,4}$/;
    if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 4) {
        if (!reg.test(money)) {
            var end = money.toString().split(".")[1];
            if (end.length > 4) {
                end = end.substring(0, 4);
            }
            money = money.toString().split(".")[0] + "." + end;
        }
    }
    document.getElementById("tradeAmount").value = money;
    document.getElementById("limitedMoney").value = money;
    tradeTurnoverValue_new(0, null);
}
function updateSecond() {
    var second = document.getElementById("updateSecond").value;
    var secondCookie = new CookieClass();
    secondCookie.setCookie("REFRESH_HANDLEENTRUST_TIME", second);
    if (entrustTime != null) {
        clearTimeout(entrustTime);
    }
    if (updateTime != null) {
        clearInterval(updateTime);
    }
    updateNumber = second / 1000 - 1;
    updateTime = setInterval(updateNumberFun, 1000);

    if (typeof(isConnect) != 'undefined' && isConnect) {
        var symbol = document.getElementById("symbol").value;
        //newCoinLabel
        if (symbol == 0) {//btc
            var jsonObject = {
                '@class': 'com.okcoin.push.message.in.PushSettings',
                interval: updateNumber + 1,
                type: 'r_btc5Depth_ticker'
            };
            socket.json.send(jsonObject);
        } else if (symbol == 1) {
            var jsonObject = {
                '@class': 'com.okcoin.push.message.in.PushSettings',
                interval: updateNumber + 1,
                type: 'r_ltc5Depth_ticker'
            };
            socket.json.send(jsonObject);
        }
    } else {
        entrustTime = setTimeout("handleEntrust(" + second + ")", second);
    }
}
var pushIntervalTime = 2;
function limitedTypeChange() {
    if (document.getElementById("limitedType").checked) {
        document.getElementById("treadContTextDiv").style.display = "none";
        document.getElementById("treadContDiv").style.display = "none";
        document.getElementById("limitedDiv").style.display = "";
    } else {
        document.getElementById("treadContTextDiv").style.display = "";
        document.getElementById("treadContDiv").style.display = "";
        document.getElementById("limitedDiv").style.display = "none";
        document.getElementById("tradeCnyPrice").focus();
    }
    document.getElementById("tradeAmount").value = 0;
    document.getElementById("limitedMoney").value = 0;
    limitedSummoneyValue();
    tradeTurnoverValue2(2, document.getElementById("tradeAmount"));
    document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne";
    document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo";
    document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree";


}
function onPortion(portion) {
    var tradeType = document.getElementById("tradeType").value;
    if (tradeType == 0) {
        var money = Number(document.getElementById("userCnyBalance").value);
        var portionMoney = accMul(money, portion);
        antoTurnover(portionMoney);
    } else {
        var money = Number(document.getElementById("userCoinBalance").value);
        var portionMoney = accMul(money, portion);
        antoAmount(portionMoney);
    }
}

function planBuyLimitedTypeChange(obj, type) {
    var value = obj.value;
    var symbol = document.getElementById("playSymobl").value;
    var symbolStr = SYMBOLS_UTIL.symbolStr2[symbol];
    var isopen = document.getElementById("isopen").value;
    var footsetFlag = document.getElementById("footsetFlag").value;
    if (value == 1) {
        document.getElementById("planBuyTotalInformation").style.display = "none";
        document.getElementById("planBuyInputCny").style.display = "none";
        document.getElementById("planBuyInputCnyTwo").style.display = "";
        document.getElementById("planBuyCny").innerHTML = " ";
        document.getElementById("planBuyChen").style.display = "none";
        document.getElementById("planBuyEqual").style.display = "none";
        document.getElementById("buyinput_strategy").style.paddingTop = "20px";
        if (isopen == 1) {
            document.getElementById("buyonesellone").style.height = "377px";
        } else {
            document.getElementById("buyonesellone").style.height = "436px";
        }
        document.getElementById("triggerPriceTigs").style.display = "";
        document.getElementById("planBuyInputPrice").style.display = "none";
        jQuery("#planBuyInputAmount").removeClass("buyinputnum-2");
        jQuery("#planBuyInputAmount").addClass("Newbuyinputnum");
        if (document.getElementById("iconStationCueBuy")) {
            document.getElementById("iconStationCueBuy").innerHTML = whenthepriceof + symbolStr + priceequaltopriceyouset
        }
        if (footsetFlag == 2) {
            //newCoinLabel
            if (symbol == 1) {
                jQuery("#buyAmount").removeClass("planInput_priceLtc");
            } else if (symbol == 0) {
                jQuery("#buyAmount").removeClass("planInput_priceBtc");
            } else if (symbol == 2) {
                jQuery("#buyAmount").removeClass("planInput_priceBtc");
            }
            jQuery("#buyAmount").addClass("planInput_usd");
        } else {
            //newCoinLabel
            if (symbol == 1) {
                jQuery("#buyAmount").removeClass("planInput_priceLtc");
            } else if (symbol == 0) {
                jQuery("#buyAmount").removeClass("planInput_priceBtc");
            } else if (symbol == 2) {
                jQuery("#buyAmount").removeClass("planInput_priceBtc");
            }
            jQuery("#buyAmount").addClass("planInput_cny");
        }

    } else {
        document.getElementById("planBuyTotalInformation").style.display = "";
        document.getElementById("planBuyPrice").style.display = "";
        document.getElementById("planBuyPriceTwo").style.display = "none";
        document.getElementById("planBuyInputCny").style.display = "";
        document.getElementById("planBuyInputCnyTwo").style.display = "none";
        document.getElementById("planBuyAmount").style.display = "";
        document.getElementById("planBuyAmountTwo").style.display = "none";
        document.getElementById("planBuyCny").innerHTML = get$("buyselltotalprice");
        document.getElementById("planBuyChen").style.display = "";
        document.getElementById("planBuyEqual").style.display = "";
        document.getElementById("buyinput_strategy").style.paddingTop = "0px";
        if (isopen == 1) {
            document.getElementById("buyonesellone").style.height = "383px";
        } else {
            document.getElementById("buyonesellone").style.height = "442px";
        }

        document.getElementById("planBuyInputPrice").style.display = "";
        document.getElementById("triggerPriceTigs").style.display = "none";
        jQuery("#planBuyInputAmount").removeClass("Newbuyinputnum");
        jQuery("#planBuyInputAmount").addClass("buyinputnum-2");
        if (document.getElementById("iconStationCueBuy")) {
            document.getElementById("iconStationCueBuy").innerHTML = whenthepriceof + symbolStr + "价格达到您设置的触发价格时，系统将自动按您设置的委托价与购买数量下达限价委托单。";
        }
        if (footsetFlag == 2) {
            jQuery("#buyAmount").removeClass("planInput_usd");
            //newCoinLabel
            if (symbol == 1) {
                jQuery("#buyAmount").addClass("planInput_priceLtc");
            } else if (symbol == 0) {
                jQuery("#buyAmount").addClass("planInput_priceBtc");
            } else if (symbol == 2) {
                jQuery("#buyAmount").addClass("planInput_priceBtc");
            }
        } else {
            jQuery("#buyAmount").removeClass("planInput_cny");
            //newCoinLabel
            if (symbol == 1) {
                jQuery("#buyAmount").addClass("planInput_priceLtc");
            } else if (symbol == 0) {
                jQuery("#buyAmount").addClass("planInput_priceBtc");
            } else if (symbol == 2) {
                jQuery("#buyAmount").addClass("planInput_priceBtc");
            }
        }
//        jQuery("#buyAmount").removeClass("planInputUsd");
//        jQuery("#buyAmount").addClass("planInput_priceCny");
    }
}

function planSellLimitedTypeChange(obj, type) {
    var value = obj.value;
    var symbol = document.getElementById("playSymobl").value;
    var isopen = document.getElementById("isopen").value;
    var symbolStr = SYMBOLS_UTIL.symbolStr2[symbol];
    if (value == 1) {
        document.getElementById("planSellTotalInformation").style.display = "none";
        document.getElementById("planSellInputCny").style.display = "none";
        document.getElementById("planSellInputCnyTwo").style.display = "";
        document.getElementById("planSellCny").innerHTML = " ";
        document.getElementById("planSellChen").style.display = "none";
        document.getElementById("planSellEqual").style.display = "none";
        document.getElementById("sellinput_strategy").style.paddingTop = "20px";
        if (isopen == 1) {
            document.getElementById("buyonesellone").style.height = "377px";
        } else {
            document.getElementById("buyonesellone").style.height = "436px";
        }

        document.getElementById("planSellInputPrice").style.display = "none";

        document.getElementById("sellTriggerPriceTigs").style.display = "";
        jQuery("#planSellInputAmount").removeClass("buyinputnum-2");
        jQuery("#planSellInputAmount").addClass("Newbuyinputnum");
        if (document.getElementById("iconStationCueSell")) {
            document.getElementById("iconStationCueSell").innerHTML = whenthepriceof + symbolStr + priceequalpredeterminedpriceyouset;
        }
        //newCoinLabel
        if (symbol == 1) {
            jQuery("#sellAmount").addClass("planInput_Ltc");
            jQuery("#sellAmount").removeClass(".planInput_priceLtc");
        } else if (symbol == 0) {
            jQuery("#sellAmount").addClass("planInput_Btc");
            jQuery("#sellAmount").removeClass(".planInput_priceBtc");
        } else if (symbol == 2) {
            jQuery("#sellAmount").addClass("planInput_Btc");
            jQuery("#sellAmount").removeClass(".planInput_priceBtc");
        }
//        jQuery("#sellAmount").removeClass("planInput");
//        jQuery("#sellAmount").addClass("planInputUsd ");
    } else {
        document.getElementById("planSellTotalInformation").style.display = "";
        document.getElementById("planSellPrice").style.display = "";
        document.getElementById("planSellPriceTwo").style.display = "none";
        document.getElementById("planSellInputCny").style.display = "";
        document.getElementById("planSellInputCnyTwo").style.display = "none";
        document.getElementById("planSellCny").innerHTML = get$("buyselltotalprice");
        document.getElementById("planSellChen").style.display = "";
        document.getElementById("planSellEqual").style.display = "";
        document.getElementById("planSellAmount").style.display = "";
        document.getElementById("sellinput_strategy").style.paddingTop = "0px";
        if (isopen == 1) {
            document.getElementById("buyonesellone").style.height = "383px";
        } else {
            document.getElementById("buyonesellone").style.height = "442px";
        }

        document.getElementById("planSellInputPrice").style.display = "";
        document.getElementById("sellTriggerPriceTigs").style.display = "none";
        jQuery("#planSellInputAmount").removeClass("Newbuyinputnum");
        jQuery("#planSellInputAmount").addClass("buyinputnum-2");
        if (document.getElementById("iconStationCueSell")) {
            document.getElementById("iconStationCueSell").innerHTML = whenthepriceof + symbolStr + "价格达到您设置的触发价格时，系统将自动按您设置的委托价与卖出数量下达限价委托单。";
        }
        //newCoinLabel
        if (symbol == 1) {
            jQuery("#sellAmount").addClass("planInput_priceLtc");
            jQuery("#sellAmount").removeClass("planInput_Ltc");
        } else if (symbol == 0) {
            jQuery("#sellAmount").addClass("planInput_priceBtc");
            jQuery("#sellAmount").removeClass("planInput_Btc");
        } else if (symbol == 2) {
            jQuery("#sellAmount").addClass("planInput_priceBtc");
            jQuery("#sellAmount").removeClass("planInput_Btc");
        }
        // jQuery("#sellAmount").setAttribute("style","width:200px");
//        jQuery("#sellAmount").removeClass("planInputUsd");
//        jQuery("#sellAmount").addClass("planInput");
    }
}
//type =0 :最近10笔委托 type=1 历史成交
function entrustInfo(type) {
    var url = "/trade/entrustInfo.do?type=" + type + "&random=" + Math.round(Math.random() * 100);

    jQuery("#realEntrustType").val(type);
    var loadId = "entrustInfo";
    if (type == 2) {
        loadId = "entrustInfoHis";
        jQuery("#entrustInfo").hide();
        jQuery("#entrustInfoHis").show();
    } else {
        jQuery("#entrustInfo").show();
        jQuery("#entrustInfoHis").hide();
    }

    jQuery("#" + loadId).load(url, null, function (data) {
    });
}
var limitedTypeChangeOld;
var sell_oldPrice; //
var buy_oldPrice; //
var sell_oldAmount;//id ="tradeAmount"
var buy_oldAmount;
function autoChangeBuyAndSell(type) {

    var _symBolStr = document.getElementById("symbol").value;
    var _tradeType = document.getElementById("tradeType").value;
    if (_tradeType == type) {
        return;
    }
    if (type == 0) {
        sell_oldPrice = document.getElementById('tradeCnyPrice').value;
        sell_oldAmount = document.getElementById('tradeAmount').value;
    } else {
        buy_oldPrice = document.getElementById('tradeCnyPrice').value;
        buy_oldAmount = document.getElementById('tradeAmount').value;
    }


    var temp_LimitedType = false; //记录是否市价交易。
    temp_LimitedType = document.getElementById("limitedType").checked;
    document.getElementById("limitedType").checked = limitedTypeChangeOld;
    limitedTypeChangeOld = temp_LimitedType;

    limitedTypeChange();
    if (_tradeType == type) {
        return;
    } else {

        var _self_cookie = new CookieClass();
        _self_cookie.setCookie("tradetype", type + '');
        if (type == 0) {
            var localSellPrice = 0;
            // newCoinLabel
            if (_symBolStr == '0') {
                localSellPrice = push.btcsell;
            } else if (_symBolStr == '1') {
                localSellPrice = push.ltcsell;
            } else if (_symBolStr == '2') {
                localSellPrice = push.ethsell;
            }
            buy_oldPrice = (buy_oldPrice == 0 || buy_oldPrice == undefined) ? localSellPrice : buy_oldPrice;
            buy_oldAmount = (buy_oldAmount == 0 || buy_oldAmount == undefined) ? 0 : buy_oldAmount;
            document.getElementById("buyDiv").style.display = "";
            document.getElementById("sellDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "";
            document.getElementById("sellBtcCnyInformation").style.display = "none";
            document.getElementById("buyLi").className = "cur";
            document.getElementById("sellLi").className = "";
            document.getElementById("tradeType").value = 0;
            document.getElementById("priceSpan").innerHTML = immediatelybuy;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + buyamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = buytotalprice;
            document.getElementById("btnA").value = immediatelybuy;
            document.getElementById("btnA").className = "buttonGreen submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = holding + " : ";
            document.getElementById("userBalance").value = document.getElementById("userCnyBalance").value;
            document.getElementById("limitpriceTitle").style.color = "green";
            document.getElementById("proprotionInfo").innerHTML = buyproportion + ":";
            document.getElementById("idBar2").className = "barGreen";
            _tradeType = 0;
        } else {
            var localBuyPrice = 0;
            // newCoinLabel
            if (_symBolStr == '0') {
                localBuyPrice = push.btcbuy;
            } else if (_symBolStr == '1') {
                localBuyPrice = push.ltcbuy;
            } else if (_symBolStr == '2') {
                localBuyPrice = push.ethbuy;
            }
            sell_oldPrice = (sell_oldPrice == 0 || sell_oldPrice == undefined) ? localBuyPrice : sell_oldPrice;
            sell_oldAmount = (sell_oldAmount == 0 || sell_oldAmount == undefined) ? 0 : sell_oldAmount;
            document.getElementById("sellDiv").style.display = "";
            document.getElementById("buyDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "none";
            document.getElementById("sellBtcCnyInformation").style.display = "";
            document.getElementById("sellLi").className = "cur";
            document.getElementById("buyLi").className = "";
            document.getElementById("tradeType").value = 1;
            document.getElementById("priceSpan").innerHTML = askprice;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + sellamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = selltotalprice;
            document.getElementById("btnA").value = immediatelysell;
            document.getElementById("btnA").className = "buttonRed submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = sellnetamount + " : "
            document.getElementById("userBalance").value = document.getElementById("userCoinBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = sellproportion + ":";
            document.getElementById("idBar2").className = "barRed";
//			document.getElementById("proprotionInfo").style.color = "red";
            _tradeType = 1;
        }
        if (type == 0) {

            var strmoney = document.getElementById("userBalance").value
            var money = Number(strmoney.replace(",", ""));
            var moneyNum = accMul(buy_oldPrice, buy_oldAmount);
            var coinNum = document.getElementById('userCoinBalance').value;
            if (money < moneyNum) {
                document.getElementById("tradeCnyPrice").value = buy_oldPrice;
                document.getElementById("tradeTurnover").value = money;
                tradePercentVlaueTotal();
                summoneyValue(null);
            } else {
                var strmoney = document.getElementById("userBalance").value
                var money = Number(strmoney.replace(",", ""));
                var moneyNum = accMul(buy_oldPrice, buy_oldAmount);
                var coinNum = document.getElementById('userCoinBalance').value;
                document.getElementById("tradeCnyPrice").value = buy_oldPrice;
                document.getElementById("tradeAmount").value = floor(accDiv(moneyNum, buy_oldPrice), 4);
                tradePercentVlaueTwoPart(floor(moneyNum, 2), money);
                tradeTurnoverValue();
            }
        } else {

            var strmoney = document.getElementById("userBalance").value
            var money = Number(strmoney.replace(",", ""));
            var moneyNum = accMul(sell_oldPrice, sell_oldAmount);
            var coinNum = document.getElementById('userCoinBalance').value;
            if (money < moneyNum) {
                document.getElementById("tradeAmount").value = sell_oldAmount;
                document.getElementById("tradeCnyPrice").value = sell_oldPrice;
                tradePercentVlaueTotal();
                tradeTurnoverValue();
            } else {
                document.getElementById("tradeCnyPrice").value = sell_oldPrice;
                document.getElementById("tradeAmount").value = sell_oldAmount;
                tradePercentVlaueTwoPart(moneyNum, money);
                tradeTurnoverValue();
            }
        }

    }
}

//全部卖出
function pageSellAllCoin() {
    var _currentSymbolValue = document.getElementById('symbol').value;
    var coinNum = 0;
    // TODO newCoinLabel
    if (_currentSymbolValue == 0) {
        coinNum = Number(document.getElementById("bannerUserBtcBalance").value);
    } else if (_currentSymbolValue == 1) {
        coinNum = Number(document.getElementById("bannerUserLtcBalance").value);
    } else if (_currentSymbolValue == 2) {
        coinNum = Number(document.getElementById("bannerUserEthBalance").value);
    }
    antoAmount(coinNum);
}
//全部买入
function buyCoinUseAllCny() {
    var _cnyNum = Number(document.getElementById('bannerUserCnyBalance').value)
    antoTurnover(_cnyNum);
}


//type :0 默认 type=1 price type=2 amount
function tradeTurnoverValue_new(type, event) {
    var isreturn = ctrlAorTab(event);
    if (isreturn) {
        return;
    }
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var tradeAmount = 0;
    var tradeCnyPrice = 0;
    if (type == 2) {
        var amountSelectionStart = getPositionForInput(document.getElementById("tradeAmount"));
        tradeAmount = document.getElementById("tradeAmount").value = checkNumberByName("tradeAmount");
        setCursorPosition(document.getElementById("tradeAmount"), amountSelectionStart);
    } else {
        tradeAmount = document.getElementById("tradeAmount").value;
    }
    if (type == 1) {
        var priceSelectionStart = getPositionForInput(document.getElementById("tradeCnyPrice"));
        tradeCnyPrice = document.getElementById("tradeCnyPrice").value = checkNumberByName("tradeCnyPrice");
        setCursorPosition(document.getElementById("tradeCnyPrice"), priceSelectionStart);
    } else {
        tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    }
    var turnover = tradeAmount * tradeCnyPrice;
    if (turnover != null && turnover.toString().split(".") != null && turnover.toString().split(".")[1] != null && turnover.toString().split(".")[1].length > 4) {
        turnover = turnover.toFixed(4);
    }
    document.getElementById("tradeTurnover").value = turnover;
    if (tradeType == 0) {
        var tradeTurnover = tradeAmount * tradeCnyPrice;
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
            tradePercentVlaueTotal();
            alertTipsSpan2(balanceisinsufficient);
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeTurnover), Number(document.getElementById("userBalance").value));
            clearTipsSpan2();
        }
    } else {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
            //newCoinLabel
            if (symbol == 0) {
                tradePercentVlaueTotal();
                alertTipsSpan2(buytradejs2);
            } else if (symbol == 1) {
                tradePercentVlaueTotal();
                alertTipsSpan2(buytradejs3);
            } else if (symbol == 2) {
                tradePercentVlaueTotal();
                alertTipsSpan2(get$("ethNotEnough"));
            }
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeAmount), Number(document.getElementById("userBalance").value));
            clearTipsSpan2();
        }
    }
}

function submitTradeBtcForm_new() {
    if (check == 2) {
        return;
    }
    var tradeAmount = document.getElementById("tradeAmount").value;
    var tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    var tradePwd = trim(document.getElementById("tradePwd").value);
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var isopen = document.getElementById("isopen").value;
    var strategyType = document.getElementById("strategy_type").value;
    var limited = 0;
    if (strategyType == 1) {
        if (tradeType == 0) {
            var tradeTurnover = tradeAmount * tradeCnyPrice;
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
                alertTipsSpan2(balanceisinsufficient);
                return;
            } else {
                clearTipsSpan();
            }
        } else {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan2(buytradejs2);
                } else if (symbol == 1) {
                    alertTipsSpan2(buytradejs3);
                } else if (symbol == 2) {
                    alertTipsSpan2(ethNotEnough);
                }
                return;
            } else {
                clearTipsSpan();
            }
        }
        var reg = new RegExp("^[0-9]+\.{0,1}[0-9]{0,8}$");
        if (!reg.test(tradeAmount)) {
            alertTipsSpan2(buytradejs4);
            return;
        } else {
            clearTipsSpan();
        }
        //newCoinLabel
        if (symbol == 0 && tradeAmount < 0.01) {
            alertTipsSpan2(buytradejs6);
            return;
        } else if (symbol == 1 && tradeAmount < 0.1) {
            alertTipsSpan2(buytradejs5);
            return;
        } else if (symbol == 2 && tradeAmount < 0.01) {
            alertTipsSpan2(get$("ethMinBuyAmount"));
            return;
        } else {
            clearTipsSpan();
        }
        if (!reg.test(tradeCnyPrice)) {
            alertTipsSpan2(buytradejs7);
            return;
        } else {
            clearTipsSpan();
        }
    } else {
        limited = 1;
        var limitedMoney = Number(document.getElementById("limitedMoney").value);
        if (tradeType == 0) {
            //newCoinLabel
            var nowPrice = 0;
            if (symbol == 0) {
                nowPrice = accMul(0.01, Number(document.getElementById("nowPrice").value));
            } else if (symbol == 1) {
                nowPrice = accMul(0.1, Number(document.getElementById("nowPrice").value));
            } else if (symbol == 2) {
                nowPrice = accMul(0.01, Number(document.getElementById("nowPrice").value));
            }
            if (limitedMoney < nowPrice) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan2(buytradejs21);
                } else if (symbol == 1) {
                    alertTipsSpan2(buytradejs22);
                } else if (symbol == 2) {
                    alertTipsSpan2(get$("ethMinBuyAmount"));
                }
                return;
            }
        } else {
            //newCoinLabel
            if (symbol == 0) {
                if (limitedMoney < 0.01) {
                    alertTipsSpan2(selltradejs1);
                    return;
                }
            } else if (symbol == 1) {
                if (limitedMoney < 0.1) {
                    alertTipsSpan2(selltradejs2);
                    return;
                }
            } else if (symbol == 2) {
                if (limitedMoney < 0.01) {
                    alertTipsSpan2(get$("ethMinBuyAmount"));
                    return;
                }
            }
        }
        if (tradeType == 0) {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < limitedMoney) {
                alertTipsSpan2(balanceisinsufficient);
                return;
            } else {
                clearTipsSpan();
            }
            tradeCnyPrice = limitedMoney;
        } else {
            if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < limitedMoney) {
                //newCoinLabel
                if (symbol == 0) {
                    alertTipsSpan2(buytradejs2);
                } else if (symbol == 1) {
                    alertTipsSpan2(buytradejs3);
                } else if (symbol == 2) {
                    alertTipsSpan2(ethNotEnough);
                }
                return;
            } else {
                clearTipsSpan();
            }
        }
        tradeAmount = limitedMoney;
    }
    if (tradePwd == "" && isopen != 1) {
        alertTipsSpan2(entertransactionpassword);
        return;
    } else {
        document.getElementById("tradeBtcTips").style.display = "";
        document.getElementById("tradeBtcTips").innerHTML = "&nbsp;";
    }

    var url = "";
    if (tradeType == 0) {
        url = "/trade/buyBtcSubmit.do?random=" + Math.round(Math.random() * 100);
    } else {
        url = "/trade/sellBtcSubmit.do?random=" + Math.round(Math.random() * 100);
    }
    tradePwd = isopen == 1 ? "" : tradePwd;
    var param = {
        tradeAmount: tradeAmount,
        tradeCnyPrice: tradeCnyPrice,
        tradePwd: tradePwd,
        symbol: symbol,
        limited: limited
    };

    if (strategyType == 1) {
        var lastprice = jQuery("#tradeLastPrice").html().replace(",", "");
        var callback = {
            okBack: function () {
                submitTradeBtcForm_post(url, param, tradeType, symbol);
            }, noBack: void(0)
        };


        var rate = accDiv(tradeCnyPrice, lastprice);

        if (tradeType == 0 && rate >= 1.02) {
            okcoinAlert(get$("tradeorderbuyalert"), true, callback);
            return;
        }

        if (tradeType == 1 && rate <= 0.98) {
            okcoinAlert(get$("tradeordersellalert"), true, callback);
            return;
        }
    }

    submitTradeBtcForm_post(url, param, tradeType, symbol);


}


function submitTradeBtcForm_post(url, param, tradeType, symbol) {
    waitingStationStatic("btnA", insubmiting);
    check = 2;
    jQuery.post(url, param, function (data) {
        var result = eval('(' + data + ')');
        if (result != null) {
            if (result.resultCode != 0) {
                check = 1;
            }
            if (result.resultCode == -1) {
                if (tradeType == 0) {
                    //newCoinLabel
                    if (symbol == 1) alertTipsSpan2(buytradejs9);
                    else if (symbol == 0) alertTipsSpan2(buytradejs8);
                    else if (symbol == 2) alertTipsSpan2(get$("ethMinBuyAmount"));
                } else {
                    //newCoinLabel
                    if (symbol == 1) alertTipsSpan2(selltradejs4);
                    else if (symbol == 0) alertTipsSpan2(selltradejs3);
                    else if (symbol == 2) alertTipsSpan2(get$("ethMinBuyAmount"));
                }
            } else if (result.resultCode == -2) {
                if (result.errorNum == 0) {
                    alertTipsSpan2(buytradejs10);
                } else {
                    alertTipsSpan2(buytradejs11 + youhave + result.errorNum + chancesleft);
                }
                if (document.getElementById("tradePwd") != null) {
                    document.getElementById("tradePwd").value = "";
                }
            } else if (result.resultCode == -3) {
                alertTipsSpan2(buytradejs13);
            } else if (result.resultCode == -4) {
                alertTipsSpan2(buytradejs14);
            } else if (result.resultCode == -5) {
                alertTipsSpan2(buytradejs15);
            } else if (result.resultCode == -6) {
                okcoinAlert(buytradejs16, null, null, "");
            } else if (result.resultCode == -7) {
                alertTipsSpan2(buytradejs17);
                if (document.getElementById("tradePwdDiv") != null) {
                    document.getElementById("tradePwdDiv").style.display = "block";
                    document.getElementById("isopen").value = 0;
                }
            } else if (result.resultCode == -8) {
                alertTipsSpan2(entertransactionpassword);
            } else if (result.resultCode == -9) {
                alertTipsSpan2(get$("isLend"));
            } else if (result.resultCode == 0) {
                alertTipsSpan2(get$("ordersuccess"));
                jQuery('#tradePwd').val('');
                jQuery('#tradeAmount').val('0');
                jQuery('#tradeTurnover').val('0');
                jQuery('#limitedMoney').val('0');
                setTimeout(function () {
                    document.getElementById("tradeBtcTips").style.display = "";
                    document.getElementById("tradeBtcTips").innerHTML = "";
                    check = 1;
                    tradeTurnoverValue();
                }, 3000);
                if (document.getElementById("tradePwdDiv") && result.errorNum == 1000) {
                    document.getElementById("tradePwdDiv").style.display = "none";
                    document.getElementById("isopen").value = 1;
                }
            } else if (result.resultCode == 2) {
                alertTipsSpan2(buytradejs19);
            } else if (result.resultCode == -200) {
                alertTipsSpan2(get$("youfreezebymasterxia"));
            } else if (result.resultCode == 3) {
                alertTipsSpan2(buytradejs20);
            } else if (result.resultCode == -97) {
                alertTipsSpan2(get$("tradesmallamountmore"));
            }
        }
    });
    if (tradeType == 0) {
        clearWaitingStation("btnA", immediatelybuy);
    } else {
        clearWaitingStation("btnA", immediatelysell);
    }
}

function clearTipsSpan2() {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = "";
}

function clearTipsSpan_new() {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = "";
}


function alertTipsSpan2(tips) {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = tips;
}

function alertTipsSpan_new(tips) {
    document.getElementById("tradeBtcTips").style.display = "";
    document.getElementById("tradeBtcTips").innerHTML = tips;
}

//过滤输入的数字
function checkNumberByName_new(name, length) {
    var number = document.getElementById(name).value.split('.');
    if (number.length > 1) {
        return number[0].replace(/\D/g, '') + '.' + number[1].replace(/\D/g, '').slice(0, length);
    } else {
        return number[0].replace(/\D/g, '');
    }
}

function summoneyValue_new(event) {
    var isreturn = ctrlAorTab(event);
    if (isreturn) {
        return;
    }
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    var tradeTurnoverSelectionStart = getPositionForInput(document.getElementById("tradeTurnover"));
    var tradeTurnover = document.getElementById("tradeTurnover").value = checkNumberByName_new("tradeTurnover", 2);
    setCursorPosition(document.getElementById("tradeTurnover"), tradeTurnoverSelectionStart);
    var tradeCnyPrice = document.getElementById("tradeCnyPrice").value;
    var tradeAmount = document.getElementById("tradeAmount").value;
    if (tradeCnyPrice != 0) {
        tradeAmount = tradeTurnover / tradeCnyPrice;
    } else {
        tradeAmount = 0;
    }
    if (tradeAmount != null && tradeAmount.toString().split(".") != null && tradeAmount.toString().split(".")[1] != null && tradeAmount.toString().split(".")[1].length > 4) {
        //去掉四舍五入算法，改为直接截取
        //tradeAmount=tradeAmount.toFixed(5);
        //tradeAmount = tradeAmount.substring(0, tradeAmount.length-1);
        var temp = tradeAmount.toString();
        var index = temp.indexOf(".");
        if (index > -1) {
            var t = temp.substr(index + 1);

            if (t.length > 4)
                temp = temp.substring(0, index + 5);

        }
        tradeAmount = Number(temp);
    }

    document.getElementById("tradeAmount").value = tradeAmount;
    var reg = /^(-?\d*)\.?\d{1,4}$/;
    if (tradeTurnover != null && tradeTurnover.toString().split(".") != null && tradeTurnover.toString().split(".")[1] != null && tradeTurnover.toString().split(".")[1].length > 4) {
        if (!reg.test(tradeTurnover)) {
            document.getElementById("tradeTurnover").value = tradeTurnover.substring(0, tradeTurnover.length - 1);
            return false;
        }
    }
    if (tradeType == 0) {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeTurnover)) {
            tradePercentVlaueTotal();
            alertTipsSpan_new(balanceisinsufficient);
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeTurnover), Number(document.getElementById("userBalance").value));
            clearTipsSpan_new();
        }
    } else {
        if (document.getElementById("userBalance") != null && Number(document.getElementById("userBalance").value) < Number(tradeAmount)) {
            //newCoinLabel
            if (symbol == 0) {
                tradePercentVlaueTotal();
                alertTipsSpan_new(buytradejs2);
            } else if (symbol == 1) {
                tradePercentVlaueTotal();
                alertTipsSpan_new(buytradejs3);
            } else if (symbol == 2) {
                tradePercentVlaueTotal();
                alertTipsSpan_new(ethNotEnough);
            }
            return;
        } else {
            tradePercentVlaueOnePart(Number(tradeAmount), Number(document.getElementById("userBalance").value));
            clearTipsSpan_new();
        }
    }
}


function limitedTypeChange_new(data) {
    if (data == 2) {
        document.getElementById("treadContTextDiv").style.display = "none";
        document.getElementById("treadContDiv").style.display = "none";
        document.getElementById("limitedDiv").style.display = "";
    } else {
        document.getElementById("treadContTextDiv").style.display = "";
        document.getElementById("treadContDiv").style.display = "";
        document.getElementById("limitedDiv").style.display = "none";
        document.getElementById("tradeCnyPrice").focus();
    }
    document.getElementById("tradeAmount").value = 0;
    document.getElementById("limitedMoney").value = 0;
    limitedSummoneyValue();
    tradeTurnoverValue2(2, document.getElementById("tradeAmount"));
    document.getElementById("percentCirclebgPositionOne").className = "percentCirclebgPositionOne";
    document.getElementById("percentCirclebgPositionTwo").className = "percentCirclebgPositionTwo";
    document.getElementById("percentCirclebgPositionThree").className = "percentCirclebgPositionThree";
}


//type =0 :最近10笔委托 type=1 历史成交
function entrustInfo_new(type) {
    var symbol = document.getElementById("symbol").value;
    var strategyType = document.getElementById("selectValue").value;
    var sign = document.getElementById("sign").value;
    if (type == -1 && sign == 2) {
        return;
    }
    refrushRecord_push(symbol, strategyType, sign);
}

function autoChangeBuyAndSell_new(type) {
    var footsetFlag = document.getElementById("footsetFlag").value;
    var _symBolStr = document.getElementById("symbol").value;
    var _tradeType = document.getElementById("tradeType").value;
    if (_tradeType == type) {
        return;
    }
    //切换tab清除提示消息
    if (document.getElementById("tradeBtcTips") != null) {
        document.getElementById("tradeBtcTips").innerHTML = "";
    }
    if (type == 0) {
        sell_oldPrice = document.getElementById('tradeCnyPrice').value;
        sell_oldAmount = document.getElementById('tradeAmount').value;
        if (footsetFlag == 2) {
            document.getElementById("limitedMoney").className = "planInputUsd"
            document.getElementById('tradeCnyPrice').className = "buysellinput limit_inputUsd";
            document.getElementById('tradeTurnover').className = "buysellinput limit_inputUsd";
        } else {
            document.getElementById("limitedMoney").className = "planInput"
            document.getElementById('tradeCnyPrice').className = "buysellinput limit_inputCny";
            document.getElementById('tradeTurnover').className = "buysellinput limit_inputCny";
        }
    } else {
        buy_oldPrice = document.getElementById('tradeCnyPrice').value;
        buy_oldAmount = document.getElementById('tradeAmount').value;
        // newCoinLabel
        if (_symBolStr == 0) {
            document.getElementById("limitedMoney").className = "planInputBtc"
        } else if (_symBolStr == 1) {
            document.getElementById("limitedMoney").className = "planInputLtc"
        } else if (_symBolStr == 2) {
            document.getElementById("limitedMoney").className = "planInputEth"
        }
    }


    var temp_LimitedType = false; //记录是否市价交易。
    temp_LimitedType = document.getElementById("strategy_type").value;
    document.getElementById("strategy_type").selected = limitedTypeChangeOld;
    limitedTypeChangeOld = temp_LimitedType;

    limitedTypeChange_new(temp_LimitedType);
    if (_tradeType == type) {
        return;
    } else {
        var _self_cookie = new CookieClass();
        _self_cookie.setCookie("tradetype", type + '');
        if (type == 0) {
            var localSellPrice = 0;
            // newCoinLabel
            if (_symBolStr == '0') {
                localSellPrice = push.btcsell;
            } else if (_symBolStr == '1') {
                localSellPrice = push.ltcsell;
            } else if (_symBolStr == '2') {
                localSellPrice = push.ethsell;
            }
            buy_oldPrice = (buy_oldPrice == 0 || buy_oldPrice == undefined) ? localSellPrice : buy_oldPrice;
            buy_oldAmount = (buy_oldAmount == 0 || buy_oldAmount == undefined) ? 0 : buy_oldAmount;
            document.getElementById("buyDiv").style.display = "";
            document.getElementById("sellDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "";
            document.getElementById("sellBtcCnyInformation").style.display = "none";
            document.getElementById("buyLi").className = "cur";
            document.getElementById("sellLi").className = "";
            document.getElementById("tradeType").value = 0;
            document.getElementById("priceSpan").innerHTML = get$("buysellingprice");
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + get$("buysellamount") + "</span>";
            document.getElementById("summoneySpan").innerHTML = get$("buyselltotalprice");
            document.getElementById("btnA").value = immediatelybuy;
            document.getElementById("btnA").className = "buttonGreen submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = get$("buynewvalue") + ":";
            document.getElementById("userBalance").value = document.getElementById("userCnyBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = buyproportion + ":";
            document.getElementById("idBar2").className = "barGreen";
            _tradeType = 0;
        } else {
            var localBuyPrice = 0;
            // newCoinLabel
            if (_symBolStr == '0') {
                localBuyPrice = push.btcbuy
            } else if (_symBolStr == '1') {
                localBuyPrice = push.ltcbuy
            } else if (_symBolStr == '2') {
                localBuyPrice = push.ethbuy
            }
            sell_oldPrice = (sell_oldPrice == 0 || sell_oldPrice == undefined) ? localBuyPrice : sell_oldPrice;
            sell_oldAmount = (sell_oldAmount == 0 || sell_oldAmount == undefined) ? 0 : sell_oldAmount;
            document.getElementById("sellDiv").style.display = "";
            document.getElementById("buyDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "none";
            document.getElementById("sellBtcCnyInformation").style.display = "";
            document.getElementById("sellLi").className = "cur";
            document.getElementById("buyLi").className = "";
            document.getElementById("tradeType").value = 1;
            document.getElementById("priceSpan").innerHTML = get$("buysellingprice");
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + get$("buysellamount") + "</span>";
            document.getElementById("summoneySpan").innerHTML = get$("buyselltotalprice");
            document.getElementById("btnA").value = immediatelysell;
            document.getElementById("btnA").className = "buttonRed submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = get$("sellnetamount") + ":"
            document.getElementById("userBalance").value = document.getElementById("userCoinBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = sellproportion + ":";
            document.getElementById("idBar2").className = "barRed";
//			document.getElementById("proprotionInfo").style.color = "red";
            _tradeType = 1;
        }
        if (type == 0) {
            var strmoney = document.getElementById("userBalance").value
            var money = Number(strmoney.replace(",", ""));
            var moneyNum = accMul(buy_oldPrice, buy_oldAmount);
            var coinNum = document.getElementById('userCoinBalance').value;
            if (money < moneyNum) {
                document.getElementById("tradeCnyPrice").value = buy_oldPrice;
                document.getElementById("tradeTurnover").value = money;
                tradePercentVlaueTotal();
                summoneyValue(null);
            } else {
                var strmoney = document.getElementById("userBalance").value
                var money = Number(strmoney.replace(",", ""));
                var moneyNum = accMul(buy_oldPrice, buy_oldAmount);
                var coinNum = document.getElementById('userCoinBalance').value;
                document.getElementById("tradeCnyPrice").value = buy_oldPrice;
                document.getElementById("tradeAmount").value = floor(accDiv(moneyNum, buy_oldPrice), 4);
                tradePercentVlaueTwoPart(floor(moneyNum, 2), money);
                tradeTurnoverValue();
            }
        } else {

            var strmoney = document.getElementById("userBalance").value
            var money = Number(strmoney.replace(",", ""));
            var moneyNum = accMul(sell_oldPrice, sell_oldAmount);
            var coinNum = document.getElementById('userCoinBalance').value;
            if (money < moneyNum) {
                document.getElementById("tradeAmount").value = sell_oldAmount;
                document.getElementById("tradeCnyPrice").value = sell_oldPrice;
                tradePercentVlaueTotal();
                tradeTurnoverValue();
            } else {
                document.getElementById("tradeCnyPrice").value = sell_oldPrice;
                document.getElementById("tradeAmount").value = sell_oldAmount;
                tradePercentVlaueTwoPart(moneyNum, money);
                tradeTurnoverValue();
            }
        }

    }

    changeSelectOrder(temp_LimitedType);
}

function changeSelectOrder(val) {
    var protocol = document.getElementById("protocol").value;
    var footLanguageType = document.getElementById("footLanguageType").value;
    if (val != 1 && val != 2 && val != 3 && protocol == 1) {
        document.getElementById("strategy_type").value = document.getElementById("selectValue").value;
        showEntrustAgreement();
        return;
    }
    var isopen = document.getElementById("isopen").value;
    var sign = document.getElementById("sign").value;
    var tradeType = document.getElementById("tradeType").value;
    var symbol = document.getElementById("symbol").value;
    document.getElementById("realEntrustType").value = -1;
    displayAll();
//    document.getElementById("strategy_type").style.marginLeft="39px";
    if (val == 1 || val == 2) {
        document.getElementById("strategy_type").style.marginLeft = "30px";
        document.getElementById("strategy_type").style.width = "360px";
//        document.getElementById("strategy_body").style.height="377px";
        document.getElementById("buyorselldiv").style.display = "";
        document.getElementById("tradeTurnover").value = 0;
        document.getElementById("tradeAmount").value = 0;
        if (isopen == 1) {
            document.getElementById("buyonesellone").style.height = "377px";
        } else {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "407px";
                } else {
                    document.getElementById("buyonesellone").style.height = "388px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "377px";
            }
        }

        if (val == 1) {
            document.getElementById("btnA").style.marginTop = "0px";
        } else {
            document.getElementById("btnA").style.marginTop = "25.5px";
        }
        jQuery("#btnA").css("margin-left","145px");
        limitedTypeChange_new(val);
    } else if (val == 3) {//计划委托
        document.getElementById("strategy_type").style.marginLeft = "30px";
        document.getElementById("strategy_type").style.width = "320px";
        document.getElementById("plannedorder").style.display = "";
//        document.getElementById("strategy_body").style.height="377px";
        if (isopen == 1) {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "411px";
                } else {
                    document.getElementById("buyonesellone").style.height = "393px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "377px";
            }
        } else {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "464px";
                } else {
                    document.getElementById("buyonesellone").style.height = "444px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "425px";
            }
        }
        showDiv("plannedorder", tradeType);
    } else if (val == 4) {//跟踪交易
        if (footLanguageType == 1) {
            document.getElementById("strategy_type").style.marginLeft = "40px";
            document.getElementById("strategy_type").style.width = "162px";
        } else {
            document.getElementById("strategy_type").style.width = "172px";
            document.getElementById("strategy_type").style.marginLeft = "0px";
        }
        document.getElementById("trailorder").style.display = "";
//        document.getElementById("strategy_body").style.height="377px";
        if (isopen == 1) {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "412px";
                } else {
                    document.getElementById("buyonesellone").style.height = "393px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "377px";
            }
        } else {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "465px";
                } else {
                    document.getElementById("buyonesellone").style.height = "445px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "426px";
            }
        }

        showDiv("trailorder", tradeType);
    } else if (val == 5) {//冰山委托
        if (footLanguageType == 1) {
            document.getElementById("strategy_type").style.marginLeft = "60px";
            document.getElementById("strategy_type").style.width = "143px";
        } else {
            document.getElementById("strategy_type").style.marginLeft = "0px";
            document.getElementById("strategy_type").style.width = "172px";
        }
//        document.getElementById("strategy_body").style.height="425px";
        if (isopen == 1) {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "464px";
                } else {
                    document.getElementById("buyonesellone").style.height = "445px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "426px";
            }
        } else {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "516px";
                } else {
                    document.getElementById("buyonesellone").style.height = "496px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "478px";
            }
        }

        document.getElementById("icebergtrade").style.display = "";
        showDiv("icebergtrade", tradeType);
    } else if (val == 6) {//时间加权
        if (footLanguageType == 1) {
            document.getElementById("strategy_type").style.marginLeft = "40px";
            document.getElementById("strategy_type").style.width = "162px";
        } else {
            document.getElementById("strategy_type").style.marginLeft = "30px";
            document.getElementById("strategy_type").style.width = "172px";
        }
//        document.getElementById("strategy_body").style.height="530px";
        if (isopen == 1) {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "568px";
                } else {
                    document.getElementById("buyonesellone").style.height = "549px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "530px";
            }
        } else {
            if (footsetFlag == 2) {
                if (footLanguageType == 1) {
                    document.getElementById("buyonesellone").style.height = "621px";
                } else {
                    document.getElementById("buyonesellone").style.height = "601px";
                }
            } else {
                document.getElementById("buyonesellone").style.height = "582px"
            }
        }

        document.getElementById("timeweightedaverageprice").style.display = "";
        showDiv("timeweightedaverageprice", tradeType);
    }
    refrushRecord_new(symbol, val, sign);

    document.getElementById("selectValue").value = val;
    document.getElementById("strategy_type").value = val;
    selectEntrustTal(val);

}

function showDiv(divId, tradeType) {
    if (tradeType == 0) {
        document.getElementById(divId + "_buy").style.display = "";
    } else {
        document.getElementById(divId + "_sell").style.display = "";
    }
}

function displayAll() {
    document.getElementById("buyorselldiv").style.display = "none";
    document.getElementById("plannedorder").style.display = "none";
    document.getElementById("trailorder").style.display = "none";
    document.getElementById("icebergtrade").style.display = "none";
    document.getElementById("timeweightedaverageprice").style.display = "none";
    document.getElementById("plannedorder_buy").style.display = "none";
    document.getElementById("trailorder_buy").style.display = "none";
    document.getElementById("icebergtrade_buy").style.display = "none";
    document.getElementById("timeweightedaverageprice_buy").style.display = "none";
    document.getElementById("plannedorder_sell").style.display = "none";
    document.getElementById("trailorder_sell").style.display = "none";
    document.getElementById("icebergtrade_sell").style.display = "none";
    document.getElementById("timeweightedaverageprice_sell").style.display = "none";
}


function autoTrade_new(index, type, symbol) {

    var obj = document.getElementById("selectValue");
    var selectValue = obj ? obj.value : 0;
    obj.value = 1;
    document.getElementById("strategy_type").value = 1;
    changeSelectOrder(1);
    var footsetFlag = document.getElementById("footsetFlag").value;
    var _symBolStr = document.getElementById("symbol").value;
    var priceNum = 0;
    var amountNum = 0;
    var tradeType = document.getElementById("tradeType").value;
    if (tradeType == type) {
        type = type == 0 ? 1 : 0;
        if (type == 0) {
            document.getElementById("buyDiv").style.display = "";
            document.getElementById("sellDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "";
            document.getElementById("sellBtcCnyInformation").style.display = "none";
            document.getElementById("buyLi").className = "cur";
            document.getElementById("sellLi").className = "";
            document.getElementById("tradeType").value = 0;
            document.getElementById("priceSpan").innerHTML = immediatelybuy;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + buyamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = buytotalprice;
            document.getElementById("btnA").value = immediatelybuy;
            document.getElementById("btnA").className = "buttonGreen submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = get$("buynewvalue") + ":";
            document.getElementById("userBalance").value = document.getElementById("userCnyBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = buyproportion + ":";
            document.getElementById("idBar2").className = "barGreen";
            if (footsetFlag == 2) {
                document.getElementById("limitedMoney").className = "planInputUsd"
            } else {
                document.getElementById("limitedMoney").className = "planInput"
            }
            tradeType = 0;
        } else {
            document.getElementById("sellDiv").style.display = "";
            document.getElementById("buyDiv").style.display = "none";
            document.getElementById("buyBtcCnyInformation").style.display = "none";
            document.getElementById("sellBtcCnyInformation").style.display = "";
            document.getElementById("sellLi").className = "cur";
            document.getElementById("buyLi").className = "";
            document.getElementById("tradeType").value = 1;
            document.getElementById("priceSpan").innerHTML = askprice;
            document.getElementById("numSpan").innerHTML = "<span class=\"gray fontsize-14\">" + sellamount + "</span>";
            document.getElementById("summoneySpan").innerHTML = selltotalprice;
            document.getElementById("btnA").value = immediatelysell;
            document.getElementById("btnA").className = "buttonRed submitBuySell";
            document.getElementById("limitpriceTitle").innerHTML = get$("sellnetamount") + ":"
            document.getElementById("userBalance").value = document.getElementById("userCoinBalance").value;
            document.getElementById("limitpriceTitle").style.color = "gray";
            document.getElementById("proprotionInfo").innerHTML = sellproportion + ":";
            document.getElementById("idBar2").className = "barRed";
//			document.getElementById("proprotionInfo").style.color = "red";
            tradeType = 1;
            // newCoinLabel
            if (_symBolStr == 0) {
                document.getElementById("limitedMoney").className = "planInputBtc"
            } else if (_symBolStr == 1) {
                document.getElementById("limitedMoney").className = "planInputLtc"
            } else if (_symBolStr == 2) {
                document.getElementById("limitedMoney").className = "planInputBtc"
            }
        }
    }
    var name = "sell";
    if (tradeType == 1) {
        name = "buy";
    }
    var priceName = name + "Price" + index;
    priceNum = Number(document.getElementById(priceName).value);
    for (var i = 1; i <= index; i++) {
        var amountName = name + "Amount" + i;
        var amount = Number(document.getElementById(amountName).value);
        amountNum = accAdd(amountNum, amount);
    }
    var money = Number(document.getElementById("userBalance").value);
    var moneyNum = amountNum * priceNum;
    if (tradeType == 0) {
        var reg = /^(-?\d*)\.?\d{1,2}$/;
        if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 2) {
            if (!reg.test(money)) {
                var end = money.toString().split(".")[1];
                if (end.length > 2) {
                    end = end.substring(0, 2);
                }
                money = money.toString().split(".")[0] + "." + end;
            }
        }
        if (money < moneyNum) {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeTurnover").value = money;
            tradePercentVlaueTotal();
            summoneyValue_new(null);
        } else {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeAmount").value = amountNum;
            tradePercentVlaueTwoPart(moneyNum, money);
            tradeTurnoverValue_new(0, null);
        }
    } else {
        var reg = /^(-?\d*)\.?\d{1,4}$/;
        if (money != null && money.toString().split(".") != null && money.toString().split(".")[1] != null && money.toString().split(".")[1].length > 4) {
            if (!reg.test(money)) {
                var end = money.toString().split(".")[1];
                if (end.length > 4) {
                    end = end.substring(0, 4);
                }
                money = money.toString().split(".")[0] + "." + end;
            }
        }
        if (money < amountNum) {
            document.getElementById("tradeAmount").value = money;
            document.getElementById("tradeCnyPrice").value = priceNum;
            tradePercentVlaueTotal();
            tradeTurnoverValue_new(0, null);
        } else {
            document.getElementById("tradeCnyPrice").value = priceNum;
            document.getElementById("tradeAmount").value = amountNum;
            tradePercentVlaueTwoPart(moneyNum, money);
            tradeTurnoverValue_new(0, null);
        }
    }
}

jQuery(".cancelEntrustBatch").click(function () {

    //<a class="cancelEntrustBatch" href="javascript:void(0);">批量撤单</a>
    var callback = {
        okBack: function () {
            cancelBatch();
        }, noBack: null
    };
    okcoinAlert(get$("cancelAllFutureComfirm"), true, callback);


});

function cancelBatch() {
    var symbol = jQuery("#symbol").val();
    var url = "/trade/cancelEntrustBatch.do";
    var param = {symbol: symbol};
    jQuery.post(url, param, function (data) {
        alertTipsSpan2("");

        var result = eval('(' + data + ')');
        if (result != null) {

            if (result.errorCode == 0) {
                alertTipsSpan2(get$("openorderscanceled"));
            } else if (result.errorCode == -10) {
                alertTipsSpan2(get$("noopenorders"));
            } else {
                alertTipsSpan2(get$("ordersnotcanceled"));
            }
        }

    });

}